﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t208Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t208_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t208Mgr mgr = new t208Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t208(e.Parameters[t208_Filter.ParamPrefix]));
            IList<t208> list = mgr.FindAllByPage_t208(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t208_Filter.ParamPrefix]);
            t208_MainStore.DataSource = list;
            t208_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t208Mgr mgr = new t208Mgr();
            RowSelectionModel sm = t208_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t208 _t208 = new t208();
                _t208.t208_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t208(_t208))
                {
                    log.Debug("t208中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t208_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t208Mgr mgr = new t208Mgr();
            t208 _t208 = new t208();
            if (Hid.Text.Length > 0)
                _t208 = mgr.FindById_t208(int.Parse(Hid.Text));
            
			_t208.t208_01 = Txtt208_01.Text.Trim();
			_t208.t208_02 = Txtt208_02.Text.Trim();
			_t208.t208_03 = Txtt208_03.Text.Trim();
			_t208.t208_04 = Txtt208_04.Text.Trim();
			_t208.t208_05 = Txtt208_05.Text.Trim();
			_t208.t208_06 = Txtt208_06.Text.Trim();
			_t208.t208_07 = Txtt208_07.Text.Trim();
			_t208.t208_08 = Txtt208_08.Text.Trim();
			_t208.t208_09 = Txtt208_09.Text.Trim();
			_t208.t208_10 = Txtt208_10.Text.Trim();
			_t208.t208_11 = Txtt208_11.Text.Trim();
			_t208.t208_12 = Txtt208_12.Text.Trim();
			_t208.t208_13 = Txtt208_13.Text.Trim();
			_t208.t208_14 = Txtt208_14.Text.Trim();
			_t208.t208_15 = Txtt208_15.Text.Trim();
			_t208.t208_16 = Txtt208_16.Text.Trim();
			_t208.t208_17 = Txtt208_17.Text.Trim();
			_t208.t208_18 = Txtt208_18.Text.Trim();
			_t208.t208_19 = Txtt208_19.Text.Trim();
			_t208.t208_20 = Txtt208_20.Text.Trim();
			_t208.t208_21 = Txtt208_21.Text.Trim();
			_t208.t208_22 = Txtt208_22.Text.Trim();
			_t208.t208_23 = Txtt208_23.Text.Trim();
			_t208.t208_24 = Txtt208_24.Text.Trim();
			_t208.t208_25 = Txtt208_25.Text.Trim();
			_t208.t208_26 = Txtt208_26.Text.Trim();
			_t208.t208_27 = Txtt208_27.Text.Trim();
			_t208.t208_28 = Txtt208_28.Text.Trim();
			_t208.t208_29 = Txtt208_29.Text.Trim();
			_t208.t208_30 = Txtt208_30.Text.Trim();
			_t208.t208_31 = Txtt208_31.Text.Trim();
			_t208.t208_32 = Txtt208_32.Text.Trim();
			_t208.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t208(_t208);
            else
                isok = mgr.Add_t208(_t208);
            if (isok)
            {
                t208_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t208中执行了保存（插入或修改），并成功");
                t208_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}